// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CloudBlobClientWrapper.cs" company="AzureContrib (Open source library http://azurecontrib.codeplex.com)">
//   Microsoft Public License (Ms-PL)
// </copyright>
// <summary>
//   Exception for errors when handling Windows Azure Cloud Drives.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using Microsoft.WindowsAzure.StorageClient;

namespace AzureContrib.WindowsAzure.StorageClient
{
	internal class CloudBlobClientWrapper : ICloudBlobClient
	{
		private readonly CloudBlobClient cloudBlobClient;

		/// <summary>
		/// Initializes a new instance of the <see cref="CloudBlobClientWrapper"/> class. 
		/// Creates a wrapper around a <see cref="CloudBlobClient"/> and applies a contract <see cref="ICloudBlobClient"/>
		/// </summary>
		/// <param name="baseUri">
		/// The base <see cref="Uri"/> to the <see cref="CloudBlob"/>.
		/// </param>
		/// <param name="credentials">
		/// The credentials used to interact with the storage containing the <see cref="CloudBlob"/>.
		/// </param>
		internal CloudBlobClientWrapper(Uri baseUri, IStorageCredentials credentials)
		{
			cloudBlobClient = new CloudBlobClient(baseUri, credentials.Unwrap());
		}

		public event EventHandler<ResponseReceivedEventArgs> ResponseReceived
		{
			add { cloudBlobClient.ResponseReceived += value; }
			remove { cloudBlobClient.ResponseReceived -= value; }
		}

		public IStorageCredentials Credentials
		{
			get { return cloudBlobClient.Credentials.Wrap(); }
		}

		public Uri BaseUri
		{
			get { return cloudBlobClient.BaseUri; }
		}

		public RetryPolicy RetryPolicy
		{
			get { return cloudBlobClient.RetryPolicy; }
			set { cloudBlobClient.RetryPolicy = value; }
		}

		public TimeSpan Timeout
		{
			get { return cloudBlobClient.Timeout; }
			set { cloudBlobClient.Timeout = value; }
		}

		public string DefaultDelimiter
		{
			get { return cloudBlobClient.DefaultDelimiter; }
			set { cloudBlobClient.DefaultDelimiter = value; }
		}

		public long SingleBlobUploadThresholdInBytes
		{
			get { return cloudBlobClient.SingleBlobUploadThresholdInBytes; }
			set { cloudBlobClient.SingleBlobUploadThresholdInBytes = value; }
		}

		public long WriteBlockSizeInBytes
		{
			get { return cloudBlobClient.WriteBlockSizeInBytes; }
			set { cloudBlobClient.WriteBlockSizeInBytes = value; }
		}

		public long ReadAheadInBytes
		{
			get { return cloudBlobClient.ReadAheadInBytes; }
			set { cloudBlobClient.ReadAheadInBytes = value; }
		}

		public bool UseIntegrityControlForStreamReading
		{
			get { return cloudBlobClient.UseIntegrityControlForStreamReading; }
			set { cloudBlobClient.UseIntegrityControlForStreamReading = value; }
		}

		public int ParallelOperationThreadCount
		{
			get { return cloudBlobClient.ParallelOperationThreadCount; }
			set { cloudBlobClient.ParallelOperationThreadCount = value; }
		}

		public CloudPageBlob GetPageBlobReference(string blobAddress)
		{
			return cloudBlobClient.GetPageBlobReference(blobAddress);
		}

		public CloudPageBlob GetPageBlobReference(string blobAddress, DateTime? snapshotTime)
		{
			return cloudBlobClient.GetPageBlobReference(blobAddress, snapshotTime);
		}

		public CloudBlockBlob GetBlockBlobReference(string blobAddress)
		{
			return cloudBlobClient.GetBlockBlobReference(blobAddress);
		}

		public CloudBlockBlob GetBlockBlobReference(string blobAddress, DateTime? snapshotTime)
		{
			return cloudBlobClient.GetBlockBlobReference(blobAddress, snapshotTime);
		}

		public CloudBlob GetBlobReference(string blobAddress)
		{
			return cloudBlobClient.GetBlobReference(blobAddress);
		}

		public CloudBlob GetBlobReference(string blobAddress, DateTime? snapshotTime)
		{
			return cloudBlobClient.GetBlobReference(blobAddress, snapshotTime);
		}

		public CloudBlobContainer GetContainerReference(string containerAddress)
		{
			return cloudBlobClient.GetContainerReference(containerAddress);
		}

		public CloudBlobDirectory GetBlobDirectoryReference(string blobDirectoryAddress)
		{
			return cloudBlobClient.GetBlobDirectoryReference(blobDirectoryAddress);
		}

		public IEnumerable<CloudBlobContainer> ListContainers()
		{
			return cloudBlobClient.ListContainers();
		}

		public IEnumerable<CloudBlobContainer> ListContainers(string prefix)
		{
			return cloudBlobClient.ListContainers(prefix);
		}

		public IEnumerable<CloudBlobContainer> ListContainers(string prefix, ContainerListingDetails detailsIncluded)
		{
			return cloudBlobClient.ListContainers(prefix, detailsIncluded);
		}

		public ResultSegment<CloudBlobContainer> ListContainersSegmented()
		{
			return cloudBlobClient.ListContainersSegmented();
		}

		public ResultSegment<CloudBlobContainer> ListContainersSegmented(string prefix)
		{
			return cloudBlobClient.ListContainersSegmented(prefix);
		}

		public ResultSegment<CloudBlobContainer> ListContainersSegmented(string prefix, ContainerListingDetails detailsIncluded, int maxResults, ResultContinuation continuationToken)
		{
			return cloudBlobClient.ListContainersSegmented(prefix, detailsIncluded, maxResults, continuationToken);
		}

		public IAsyncResult BeginListContainersSegmented(AsyncCallback callback, object state)
		{
			return cloudBlobClient.BeginListContainersSegmented(callback, state);
		}

		public IAsyncResult BeginListContainersSegmented(string prefix, AsyncCallback callback, object state)
		{
			return cloudBlobClient.BeginListContainersSegmented(prefix, callback, state);
		}

		public IAsyncResult BeginListContainersSegmented(string prefix, ContainerListingDetails detailsIncluded, AsyncCallback callback, object state)
		{
			return cloudBlobClient.BeginListContainersSegmented(prefix, detailsIncluded, callback, state);
		}

		public IAsyncResult BeginListContainersSegmented(string prefix, ContainerListingDetails detailsIncluded, int maxResults, ResultContinuation continuationToken, AsyncCallback callback, object state)
		{
			return cloudBlobClient.BeginListContainersSegmented(prefix, detailsIncluded, maxResults, continuationToken, callback, state);
		}

		public ResultSegment<CloudBlobContainer> EndListContainersSegmented(IAsyncResult asyncResult)
		{
			return cloudBlobClient.EndListContainersSegmented(asyncResult);
		}

		public IEnumerable<IListBlobItem> ListBlobsWithPrefix(string prefix)
		{
			return cloudBlobClient.ListBlobsWithPrefix(prefix);
		}

		public IEnumerable<IListBlobItem> ListBlobsWithPrefix(string prefix, BlobRequestOptions options)
		{
			return cloudBlobClient.ListBlobsWithPrefix(prefix, options);
		}

		public ResultSegment<IListBlobItem> ListBlobsWithPrefixSegmented(string prefix)
		{
			return cloudBlobClient.ListBlobsWithPrefixSegmented(prefix);
		}

		public ResultSegment<IListBlobItem> ListBlobsWithPrefixSegmented(string prefix, BlobRequestOptions options)
		{
			return cloudBlobClient.ListBlobsWithPrefixSegmented(prefix, options);
		}

		public ResultSegment<IListBlobItem> ListBlobsWithPrefixSegmented(string prefix, int maxResults, ResultContinuation continuationToken)
		{
			return cloudBlobClient.ListBlobsWithPrefixSegmented(prefix, maxResults, continuationToken);
		}

		public ResultSegment<IListBlobItem> ListBlobsWithPrefixSegmented(string prefix, int maxResults, ResultContinuation continuationToken, BlobRequestOptions options)
		{
			return cloudBlobClient.ListBlobsWithPrefixSegmented(prefix, maxResults, continuationToken, options);
		}

		public IAsyncResult BeginListBlobsWithPrefixSegmented(string prefix, AsyncCallback callback, object state)
		{
			return cloudBlobClient.BeginListBlobsWithPrefixSegmented(prefix, callback, state);
		}

		public IAsyncResult BeginListBlobsWithPrefixSegmented(string prefix, int maxResults, ResultContinuation continuationToken, AsyncCallback callback, object state)
		{
			return cloudBlobClient.BeginListBlobsWithPrefixSegmented(prefix, maxResults, continuationToken, callback, state);
		}

		public ResultSegment<IListBlobItem> EndListBlobsWithPrefixSegmented(IAsyncResult asyncResult)
		{
			return cloudBlobClient.EndListBlobsWithPrefixSegmented(asyncResult);
		}
	}
}